package pl.edu.amu.kino.kardamon.midlet;

import java.util.Date;
import java.util.Vector;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import me.regexp.RE;
import pl.edu.amu.kino.kardamon.engine.Miasto;

public class CardamonMainMidlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private java.util.Hashtable __previousDisplayables = new java.util.Hashtable();
    private List LiniaKierunkiList;
    private TextBox WyszukajLinieBox;
    private List MenuList;
    private List LiniaPrzystankiList;
    private Alert alert;
    private Alert alert1;
    private Form WyznaczTraseForm;
    private TextField textField;
    private TextField textField1;
    private Form Pomoc;
    private StringItem stringItem4;
    private Form Autorzy;
    private StringItem stringItem3;
    private List ListaPrzystankowForm;
    private TextBox WyszukajBox;
    private List PrzystanekKierunekList;
    private List PrzystanekLinieList;
    private Command pauseMidlet;
    private Command gotoMenuOption;
    private Command previousForm;
    private Command przesiadkiCommand;
    private Command przystankiCommand;
    private Command okCommand1;
    //</editor-fold>//GEN-END:|fields|0|
    private RozkladJazdyTable rozkladJazdyTable;

    public CardamonMainMidlet() {
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    /**
     * Switches a display to previous displayable of the current displayable.
     * The <code>display</code> instance is obtain from the <code>getDisplay</code> method.
     */
    private void switchToPreviousDisplayable() {
        Displayable __currentDisplayable = getDisplay().getCurrent();
        if (__currentDisplayable != null) {
            Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable);
            if (__nextDisplayable != null) {
                switchDisplayable(null, __nextDisplayable);
            }
        }
    }
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
        LiniaKierunkiList = new List("Wybierz kierunek", Choice.IMPLICIT);//GEN-BEGIN:|0-initialize|1|0-postInitialize
        LiniaKierunkiList.addCommand(getPreviousForm());
        LiniaKierunkiList.setCommandListener(this);
        LiniaPrzystankiList = new List("Wybierz przystanek", Choice.IMPLICIT);
        LiniaPrzystankiList.addCommand(getPreviousForm());
        LiniaPrzystankiList.setCommandListener(this);
        ListaPrzystankowForm = new List("Przystanki", Choice.IMPLICIT);
        ListaPrzystankowForm.addCommand(getPreviousForm());
        ListaPrzystankowForm.setCommandListener(this);
        ListaPrzystankowForm.setSelectedFlags(new boolean[] {  });
        PrzystanekKierunekList = new List("Wybierz kierunek", Choice.IMPLICIT);
        PrzystanekKierunekList.addCommand(getPreviousForm());
        PrzystanekKierunekList.setCommandListener(this);
        PrzystanekLinieList = new List("Wybierz linie", Choice.IMPLICIT);
        PrzystanekLinieList.addCommand(getPreviousForm());
        PrzystanekLinieList.setCommandListener(this);
        pauseMidlet = new Command("Zamknij", Command.EXIT, 0);//GEN-END:|0-initialize|1|0-postInitialize
        rozkladJazdyTable = new RozkladJazdyTable();
        rozkladJazdyTable.addCommand(getPreviousForm());
        rozkladJazdyTable.addCommand(getPrzesiadkiCommand());
        rozkladJazdyTable.addCommand(getPrzystankiCommand());
        rozkladJazdyTable.setCommandListener(this);
        Miasto.instance();
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getMenuList());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
        switchDisplayable(null, getMenuList());//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        Displayable __currentDisplayable = display.getCurrent();
        if (__currentDisplayable != null  &&  nextDisplayable != null) {
            __previousDisplayables.put(nextDisplayable, __currentDisplayable);
        }
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == Autorzy) {//GEN-BEGIN:|7-commandAction|1|166-preAction
            if (command == previousForm) {//GEN-END:|7-commandAction|1|166-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|2|166-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|281-preAction
        } else if (displayable == LiniaKierunkiList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|3|281-preAction
                // write pre-action user code here
                LiniaKierunkiListAction();//GEN-LINE:|7-commandAction|4|281-postAction
                // write post-action user code here
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|5|283-preAction
                // write pre-action user code here
                switchDisplayable(null, getWyszukajLinieBox());//GEN-LINE:|7-commandAction|6|283-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|7|272-preAction
        } else if (displayable == LiniaPrzystankiList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|7|272-preAction
                // write pre-action user code here
                LiniaPrzystankiListAction();//GEN-LINE:|7-commandAction|8|272-postAction
                // write post-action user code here
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|9|274-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|10|274-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|200-preAction
        } else if (displayable == ListaPrzystankowForm) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|11|200-preAction
                // write pre-action user code here
                ListaPrzystankowFormAction();//GEN-LINE:|7-commandAction|12|200-postAction
                // write post-action user code here
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|13|202-preAction
                // write pre-action user code here
                switchDisplayable(null, getWyszukajBox());//GEN-LINE:|7-commandAction|14|202-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|15|27-preAction
        } else if (displayable == MenuList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|15|27-preAction
                // write pre-action user code here
                MenuListAction();//GEN-LINE:|7-commandAction|16|27-postAction
                // write post-action user code here
            } else if (command == gotoMenuOption) {//GEN-LINE:|7-commandAction|17|56-preAction
                // write pre-action user code here
                MenuListAction();//GEN-LINE:|7-commandAction|18|56-postAction
                // write post-action user code here
            } else if (command == pauseMidlet) {//GEN-LINE:|7-commandAction|19|51-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|20|51-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|21|170-preAction
        } else if (displayable == Pomoc) {
            if (command == previousForm) {//GEN-END:|7-commandAction|21|170-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|22|170-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|23|236-preAction
        } else if (displayable == PrzystanekKierunekList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|23|236-preAction
                // write pre-action user code here
                PrzystanekKierunekListAction();//GEN-LINE:|7-commandAction|24|236-postAction
                // write post-action user code here
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|25|244-preAction
                // write pre-action user code here
                switchDisplayable(null, PrzystanekLinieList);//GEN-LINE:|7-commandAction|26|244-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|27|226-preAction
        } else if (displayable == PrzystanekLinieList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|27|226-preAction
                // write pre-action user code here
                PrzystanekLinieListAction();//GEN-LINE:|7-commandAction|28|226-postAction
                // write post-action user code here
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|29|228-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|30|228-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|31|222-preAction
        } else if (displayable == WyszukajBox) {
            if (command == okCommand1) {//GEN-END:|7-commandAction|31|222-preAction
                String wzor = WyszukajBox.getString().toUpperCase();
                ListaPrzystankowForm.deleteAll();
                Vector przystanek = Miasto.instance().getPrzystanki();
                for (int i = 0; i < przystanek.size(); i++) {
                    if (((String) przystanek.elementAt(i)).toUpperCase().startsWith(wzor)) {
                        ListaPrzystankowForm.append((String) przystanek.elementAt(i), null);
                    }
                }
                method1();//GEN-LINE:|7-commandAction|32|222-postAction
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|33|300-preAction
                switchDisplayable(null, getMenuList());//GEN-LINE:|7-commandAction|34|300-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|35|305-preAction
        } else if (displayable == WyszukajLinieBox) {
            if (command == okCommand1) {//GEN-END:|7-commandAction|35|305-preAction
//                Vector kierunki = Miasto.instance().getLiniaKierunki(WyszukajLinieBox.getString(), 0);
//                if (kierunki.size() == 0) {
//                    alert.setTimeout(2000);
//                    switchDisplayable(alert, WyszukajLinieBox);
//                } else {
//                    LiniaKierunkiList.deleteAll();
//                    for (int i = 0; i < kierunki.size(); i++) {
//                        LiniaKierunkiList.append((String) kierunki.elementAt(i), null);
//                    }
//                    switchDisplayable(null, LiniaKierunkiList);
//                }
                method();//GEN-LINE:|7-commandAction|36|305-postAction
            } else if (command == previousForm) {//GEN-LINE:|7-commandAction|37|297-preAction
                switchDisplayable(null, getMenuList());//GEN-LINE:|7-commandAction|38|297-postAction
            }//GEN-BEGIN:|7-commandAction|39|64-preAction
        } else if (displayable == WyznaczTraseForm) {
            if (command == previousForm) {//GEN-END:|7-commandAction|39|64-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|40|64-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|41|7-postCommandAction
        }//GEN-END:|7-commandAction|41|7-postCommandAction
 else if (displayable == rozkladJazdyTable) {
            if (command == previousForm) {
                switchDisplayable(null, MenuList);
            } else if (command == przesiadkiCommand) {
                PrzystanekLinieList.deleteAll();
                Vector linie = Miasto.instance().getLiniePrzystanku(Miasto.instance().getWybranyPrzystanek());
                for (int i = 0; i < linie.size(); i++) {
                    PrzystanekLinieList.append((String) linie.elementAt(i), null);
                }
                switchDisplayable(null, PrzystanekLinieList);
            } else if (command == przystankiCommand) {
                LiniaPrzystankiList.deleteAll();
                Vector przystanki = Miasto.instance().getPrzystankiNaLinii(Miasto.instance().getWybranyKierunek());
                for (int i = 0; i < przystanki.size(); i++) {
                    LiniaPrzystankiList.append((String) przystanki.elementAt(i), null);
                }
                switchDisplayable(null, LiniaPrzystankiList);
            }
        }
    }//GEN-BEGIN:|7-commandAction|42|
    //</editor-fold>//GEN-END:|7-commandAction|42|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: MenuList ">//GEN-BEGIN:|25-getter|0|25-preInit
    /**
     * Returns an initiliazed instance of MenuList component.
     * @return the initialized component instance
     */
    public List getMenuList() {
        if (MenuList == null) {//GEN-END:|25-getter|0|25-preInit
            // write pre-init user code here
            MenuList = new List("Cardamon", Choice.IMPLICIT);//GEN-BEGIN:|25-getter|1|25-postInit
            MenuList.append("Pokaz rozklad linii", null);
            MenuList.append("Pokaz rozklady na przystanku", null);
            MenuList.append("Wyznacz trase", null);
            MenuList.append("Ustawienia", null);
            MenuList.append("Pomoc", null);
            MenuList.append("Autorzy", null);
            MenuList.addCommand(pauseMidlet);
            MenuList.addCommand(getGotoMenuOption());
            MenuList.setCommandListener(this);
            MenuList.setSelectCommand(getGotoMenuOption());
            MenuList.setSelectedFlags(new boolean[] { true, false, false, false, false, false });//GEN-END:|25-getter|1|25-postInit
            // write post-init user code here
        }//GEN-BEGIN:|25-getter|2|
        return MenuList;
    }
    //</editor-fold>//GEN-END:|25-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: MenuListAction ">//GEN-BEGIN:|25-action|0|25-preAction
    /**
     * Performs an action assigned to the selected list element in the MenuList component.
     */
    public void MenuListAction() {//GEN-END:|25-action|0|25-preAction
        // enter pre-action user code here
        String __selectedString = getMenuList().getString(getMenuList().getSelectedIndex());//GEN-BEGIN:|25-action|1|29-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Pokaz rozklad linii")) {//GEN-END:|25-action|1|29-preAction
                // write pre-action user code here
                switchDisplayable(null, getWyszukajLinieBox());//GEN-LINE:|25-action|2|29-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Pokaz rozklady na przystanku")) {//GEN-LINE:|25-action|3|30-preAction
                // write pre-action user code here
//                ListaPrzystankowForm.deleteAll();
//                Vector przystanki = Miasto.instance().getPrzystanki();
//                for (int i = 0; i < przystanki.size(); i++) {
//
//                    ListaPrzystankowForm.append((String) przystanki.elementAt(i), null);
//                }
                switchDisplayable(null, getWyszukajBox());//GEN-LINE:|25-action|4|30-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Wyznacz trase")) {//GEN-LINE:|25-action|5|90-preAction
                // write pre-action user code here
                switchDisplayable(null, getWyznaczTraseForm());//GEN-LINE:|25-action|6|90-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Ustawienia")) {//GEN-LINE:|25-action|7|91-preAction
                // write pre-action user code here
//GEN-LINE:|25-action|8|91-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Pomoc")) {//GEN-LINE:|25-action|9|92-preAction
                // write pre-action user code here
                switchDisplayable(null, getPomoc());//GEN-LINE:|25-action|10|92-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Autorzy")) {//GEN-LINE:|25-action|11|163-preAction
                // write pre-action user code here
                switchDisplayable(null, getAutorzy());//GEN-LINE:|25-action|12|163-postAction
                // write post-action user code here
            }//GEN-BEGIN:|25-action|13|25-postAction
        }//GEN-END:|25-action|13|25-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|25-action|14|
    //</editor-fold>//GEN-END:|25-action|14|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: gotoMenuOption ">//GEN-BEGIN:|43-getter|0|43-preInit
    /**
     * Returns an initiliazed instance of gotoMenuOption component.
     * @return the initialized component instance
     */
    public Command getGotoMenuOption() {
        if (gotoMenuOption == null) {//GEN-END:|43-getter|0|43-preInit
            // write pre-init user code here
            gotoMenuOption = new Command("Wybierz", Command.OK, 0);//GEN-LINE:|43-getter|1|43-postInit
            // write post-init user code here
        }//GEN-BEGIN:|43-getter|2|
        return gotoMenuOption;
    }
    //</editor-fold>//GEN-END:|43-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: previousForm ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initiliazed instance of previousForm component.
     * @return the initialized component instance
     */
    public Command getPreviousForm() {
        if (previousForm == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            previousForm = new Command("Cofnij", Command.EXIT, 0);//GEN-LINE:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return previousForm;
    }
    //</editor-fold>//GEN-END:|46-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: WyznaczTraseForm ">//GEN-BEGIN:|61-getter|0|61-preInit
    /**
     * Returns an initiliazed instance of WyznaczTraseForm component.
     * @return the initialized component instance
     */
    public Form getWyznaczTraseForm() {
        if (WyznaczTraseForm == null) {//GEN-END:|61-getter|0|61-preInit
            // write pre-init user code here
            WyznaczTraseForm = new Form("Wyznacz tras\u0119", new Item[] { getTextField(), getTextField1() });//GEN-BEGIN:|61-getter|1|61-postInit
            WyznaczTraseForm.addCommand(getPreviousForm());
            WyznaczTraseForm.setCommandListener(this);//GEN-END:|61-getter|1|61-postInit
            // write post-init user code here
        }//GEN-BEGIN:|61-getter|2|
        return WyznaczTraseForm;
    }
    //</editor-fold>//GEN-END:|61-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Autorzy ">//GEN-BEGIN:|164-getter|0|164-preInit
    /**
     * Returns an initiliazed instance of Autorzy component.
     * @return the initialized component instance
     */
    public Form getAutorzy() {
        if (Autorzy == null) {//GEN-END:|164-getter|0|164-preInit
            // write pre-init user code here
            Autorzy = new Form("Autorzy", new Item[] { getStringItem3() });//GEN-BEGIN:|164-getter|1|164-postInit
            Autorzy.addCommand(getPreviousForm());
            Autorzy.setCommandListener(this);//GEN-END:|164-getter|1|164-postInit
            // write post-init user code here
        }//GEN-BEGIN:|164-getter|2|
        return Autorzy;
    }
    //</editor-fold>//GEN-END:|164-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem3 ">//GEN-BEGIN:|167-getter|0|167-preInit
    /**
     * Returns an initiliazed instance of stringItem3 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem3() {
        if (stringItem3 == null) {//GEN-END:|167-getter|0|167-preInit
            // write pre-init user code here
            stringItem3 = new StringItem("", "Sekcja Inzynierii Oprogramowania Ko\u0142a Naukowego Informatyk\u00F3w Wydzia\u0142 Matematyki i Informatyki Uniwersytetu im. A. Mickiewicza w Poznaniu", Item.PLAIN);//GEN-LINE:|167-getter|1|167-postInit
            // write post-init user code here
        }//GEN-BEGIN:|167-getter|2|
        return stringItem3;
    }
    //</editor-fold>//GEN-END:|167-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Pomoc ">//GEN-BEGIN:|169-getter|0|169-preInit
    /**
     * Returns an initiliazed instance of Pomoc component.
     * @return the initialized component instance
     */
    public Form getPomoc() {
        if (Pomoc == null) {//GEN-END:|169-getter|0|169-preInit
            // write pre-init user code here
            Pomoc = new Form("Pomoc", new Item[] { getStringItem4() });//GEN-BEGIN:|169-getter|1|169-postInit
            Pomoc.addCommand(getPreviousForm());
            Pomoc.setCommandListener(this);//GEN-END:|169-getter|1|169-postInit
            // write post-init user code here
        }//GEN-BEGIN:|169-getter|2|
        return Pomoc;
    }
    //</editor-fold>//GEN-END:|169-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem4 ">//GEN-BEGIN:|175-getter|0|175-preInit
    /**
     * Returns an initiliazed instance of stringItem4 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem4() {
        if (stringItem4 == null) {//GEN-END:|175-getter|0|175-preInit
            // write pre-init user code here
            stringItem4 = new StringItem("", "Tutaj bedzie umieszczona pomoc dla tego programu");//GEN-LINE:|175-getter|1|175-postInit
            // write post-init user code here
        }//GEN-BEGIN:|175-getter|2|
        return stringItem4;
    }
    //</editor-fold>//GEN-END:|175-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: ListaPrzystankowFormAction ">//GEN-BEGIN:|199-action|0|199-preAction
    /**
     * Performs an action assigned to the selected list element in the ListaPrzystankowForm component.
     */
    public void ListaPrzystankowFormAction() {//GEN-END:|199-action|0|199-preAction
        // enter pre-action user code here
        String __selectedString = ListaPrzystankowForm.getString(ListaPrzystankowForm.getSelectedIndex());//GEN-LINE:|199-action|1|199-postAction
        // enter post-action user code here
        PrzystanekLinieList.deleteAll();
        Vector linie = Miasto.instance().getLiniePrzystanku(__selectedString);
        //System.out.println(((Linia)Baza.getInstance().getListeLiniiNaPrzystanku("572").firstElement()).getNazwa());
        //System.out.println(Baza.getInstance().getListeDefinicjiLinii().firstElement());
        for (int i = 0; i < linie.size(); i++) {
            PrzystanekLinieList.append((String) linie.elementAt(i), null);
        }

        switchDisplayable(null, PrzystanekLinieList);


    }//GEN-BEGIN:|199-action|2|
    //</editor-fold>//GEN-END:|199-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: WyszukajBox ">//GEN-BEGIN:|219-getter|0|219-preInit
    /**
     * Returns an initiliazed instance of WyszukajBox component.
     * @return the initialized component instance
     */
    public TextBox getWyszukajBox() {
        if (WyszukajBox == null) {//GEN-END:|219-getter|0|219-preInit
            // write pre-init user code here
            WyszukajBox = new TextBox("Wyszukaj", null, 100, TextField.ANY);//GEN-BEGIN:|219-getter|1|219-postInit
            WyszukajBox.addCommand(getOkCommand1());
            WyszukajBox.addCommand(getPreviousForm());
            WyszukajBox.setCommandListener(this);//GEN-END:|219-getter|1|219-postInit
            // write post-init user code here
        }//GEN-BEGIN:|219-getter|2|
        return WyszukajBox;
    }
    //</editor-fold>//GEN-END:|219-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|221-getter|0|221-preInit
    /**
     * Returns an initiliazed instance of okCommand1 component.
     * @return the initialized component instance
     */
    public Command getOkCommand1() {
        if (okCommand1 == null) {//GEN-END:|221-getter|0|221-preInit
            // write pre-init user code here
            okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|221-getter|1|221-postInit
            // write post-init user code here
        }//GEN-BEGIN:|221-getter|2|
        return okCommand1;
    }
    //</editor-fold>//GEN-END:|221-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: PrzystanekLinieListAction ">//GEN-BEGIN:|225-action|0|225-preAction
    /**
     * Performs an action assigned to the selected list element in the PrzystanekLinieList component.
     */
    public void PrzystanekLinieListAction() {//GEN-END:|225-action|0|225-preAction
        // enter pre-action user code here
        String __selectedString = PrzystanekLinieList.getString(PrzystanekLinieList.getSelectedIndex());//GEN-LINE:|225-action|1|225-postAction
        // enter post-action user code here
        PrzystanekKierunekList.deleteAll();
        Vector kierunki = Miasto.instance().getLiniaKierunki(__selectedString, 1);
        for (int i = 0; i < kierunki.size(); i++) {
            PrzystanekKierunekList.append((String) kierunki.elementAt(i), null);
        }

        switchDisplayable(null, PrzystanekKierunekList);
    }//GEN-BEGIN:|225-action|2|
    //</editor-fold>//GEN-END:|225-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: PrzystanekKierunekListAction ">//GEN-BEGIN:|235-action|0|235-preAction
    /**
     * Performs an action assigned to the selected list element in the PrzystanekKierunekList component.
     */
    public void PrzystanekKierunekListAction() {//GEN-END:|235-action|0|235-preAction
        String __selectedString = PrzystanekKierunekList.getString(PrzystanekKierunekList.getSelectedIndex());//GEN-LINE:|235-action|1|235-postAction
        Vector[] godzinyWeek = Miasto.instance().getOdjazdyLiniiNaPrzystanku(null, __selectedString);
        rozkladJazdyTable.zeruj();
        rozkladJazdyTable.setGodziny(godzinyWeek, null, null);
        rozkladJazdyTable.setLinia(Miasto.instance().getWybranaLinia());
        rozkladJazdyTable.setPrzystanek(Miasto.instance().getWybranyPrzystanek());
        System.currentTimeMillis();
        Date data = new Date(System.currentTimeMillis());
        if (data.toString().startsWith("Sun")) {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.SUNDAY);
        } else if (data.toString().startsWith("Sat")) {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.SATURDAY);
        } else {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.WEEK);
        }
        rozkladJazdyTable.repaint();
        switchDisplayable(null, rozkladJazdyTable);
    }//GEN-BEGIN:|235-action|2|
    //</editor-fold>//GEN-END:|235-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: WyszukajLinieBox ">//GEN-BEGIN:|261-getter|0|261-preInit
    /**
     * Returns an initiliazed instance of WyszukajLinieBox component.
     * @return the initialized component instance
     */
    public TextBox getWyszukajLinieBox() {
        if (WyszukajLinieBox == null) {//GEN-END:|261-getter|0|261-preInit
            // write pre-init user code here
            WyszukajLinieBox = new TextBox("Podaj nazwe linii", "", 100, TextField.NUMERIC);//GEN-BEGIN:|261-getter|1|261-postInit
            WyszukajLinieBox.addCommand(getPreviousForm());
            WyszukajLinieBox.addCommand(getOkCommand1());
            WyszukajLinieBox.setCommandListener(this);//GEN-END:|261-getter|1|261-postInit
            // write post-init user code here
        }//GEN-BEGIN:|261-getter|2|
        return WyszukajLinieBox;
    }
    //</editor-fold>//GEN-END:|261-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: LiniaPrzystankiListAction ">//GEN-BEGIN:|271-action|0|271-preAction
    /**
     * Performs an action assigned to the selected list element in the LiniaPrzystankiList component.
     */
    public void LiniaPrzystankiListAction() {//GEN-END:|271-action|0|271-preAction
        String __selectedString = LiniaPrzystankiList.getString(LiniaPrzystankiList.getSelectedIndex());//GEN-LINE:|271-action|1|271-postAction
        Vector[] godzinyWeek = Miasto.instance().getOdjazdyLiniiNaPrzystanku(__selectedString, null);
        rozkladJazdyTable.zeruj();
        rozkladJazdyTable.setGodziny(godzinyWeek, null, null);
        rozkladJazdyTable.setLinia(Miasto.instance().getWybranaLinia());
        rozkladJazdyTable.setPrzystanek(Miasto.instance().getWybranyPrzystanek());
        System.currentTimeMillis();
        Date data = new Date(System.currentTimeMillis());
        if (data.toString().startsWith("Sun")) {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.SUNDAY);
        } else if (data.toString().startsWith("Sat")) {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.SATURDAY);
        } else {
            rozkladJazdyTable.setDzien(RozkladJazdyTable.WEEK);
        }
        rozkladJazdyTable.repaint();
        switchDisplayable(null, rozkladJazdyTable);
    }//GEN-BEGIN:|271-action|2|
    //</editor-fold>//GEN-END:|271-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: LiniaKierunkiListAction ">//GEN-BEGIN:|280-action|0|280-preAction
    /**
     * Performs an action assigned to the selected list element in the LiniaKierunkiList component.
     */
    public void LiniaKierunkiListAction() {//GEN-END:|280-action|0|280-preAction
        String __selectedString = LiniaKierunkiList.getString(LiniaKierunkiList.getSelectedIndex());//GEN-LINE:|280-action|1|280-postAction
        LiniaPrzystankiList.deleteAll();
        Vector przystanki = Miasto.instance().getPrzystankiNaLinii(__selectedString);
        for (int i = 0; i < przystanki.size(); i++) {
            LiniaPrzystankiList.append((String) przystanki.elementAt(i), null);
        }

        switchDisplayable(null, LiniaPrzystankiList);
    }//GEN-BEGIN:|280-action|2|
    //</editor-fold>//GEN-END:|280-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: przesiadkiCommand ">//GEN-BEGIN:|288-getter|0|288-preInit
    /**
     * Returns an initiliazed instance of przesiadkiCommand component.
     * @return the initialized component instance
     */
    public Command getPrzesiadkiCommand() {
        if (przesiadkiCommand == null) {//GEN-END:|288-getter|0|288-preInit
            // write pre-init user code here
            przesiadkiCommand = new Command("Przesiadki", Command.ITEM, 0);//GEN-LINE:|288-getter|1|288-postInit
            // write post-init user code here
        }//GEN-BEGIN:|288-getter|2|
        return przesiadkiCommand;
    }
    //</editor-fold>//GEN-END:|288-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: przystankiCommand ">//GEN-BEGIN:|291-getter|0|291-preInit
    /**
     * Returns an initiliazed instance of przystankiCommand component.
     * @return the initialized component instance
     */
    public Command getPrzystankiCommand() {
        if (przystankiCommand == null) {//GEN-END:|291-getter|0|291-preInit
            // write pre-init user code here
            przystankiCommand = new Command("Przystanki", Command.ITEM, 1);//GEN-LINE:|291-getter|1|291-postInit
            // write post-init user code here
        }//GEN-BEGIN:|291-getter|2|
        return przystankiCommand;
    }
    //</editor-fold>//GEN-END:|291-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: method ">//GEN-BEGIN:|307-if|0|307-preIf
    /**
     * Performs an action assigned to the method if-point.
     */
    public void method() {//GEN-END:|307-if|0|307-preIf
        Vector kierunki = Miasto.instance().getLiniaKierunki(WyszukajLinieBox.getString(), 0);
        if (kierunki.size() == 0) {//GEN-LINE:|307-if|1|308-preAction
            // write pre-action user code here
            switchDisplayable(null, getAlert());//GEN-LINE:|307-if|2|308-postAction
            // write post-action user code here
        } else {//GEN-LINE:|307-if|3|309-preAction
            LiniaKierunkiList.deleteAll();
            for (int i = 0; i < kierunki.size(); i++) {
                LiniaKierunkiList.append((String) kierunki.elementAt(i), null);
            }
            switchDisplayable(null, LiniaKierunkiList);//GEN-LINE:|307-if|4|309-postAction
            // write post-action user code here
        }//GEN-LINE:|307-if|5|307-postIf
        // enter post-if user code here
    }//GEN-BEGIN:|307-if|6|
    //</editor-fold>//GEN-END:|307-if|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: alert ">//GEN-BEGIN:|311-getter|0|311-preInit
    /**
     * Returns an initiliazed instance of alert component.
     * @return the initialized component instance
     */
    public Alert getAlert() {
        if (alert == null) {//GEN-END:|311-getter|0|311-preInit
            // write pre-init user code here
            alert = new Alert("", "Nie znaleziono podanej linii.", null, AlertType.WARNING);//GEN-BEGIN:|311-getter|1|311-postInit
            alert.setTimeout(2000);//GEN-END:|311-getter|1|311-postInit
            // write post-init user code here
        }//GEN-BEGIN:|311-getter|2|
        return alert;
    }
    //</editor-fold>//GEN-END:|311-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: method1 ">//GEN-BEGIN:|314-if|0|314-preIf
    /**
     * Performs an action assigned to the method1 if-point.
     */
    public void method1() {//GEN-END:|314-if|0|314-preIf
        RE wzor = new RE(WyszukajBox.getString().toUpperCase());
        ListaPrzystankowForm.deleteAll();
        Vector przystanek = Miasto.instance().getPrzystanki();
        Vector znalezione = new Vector();
        for (int i = 0; i < przystanek.size(); i++) {
            if(wzor.match(((String) przystanek.elementAt(i)).toUpperCase())) {
                znalezione.addElement((String) przystanek.elementAt(i));
            }
        }
        if (znalezione.size() == 0) {//GEN-LINE:|314-if|1|315-preAction
            switchDisplayable(null, getAlert1());//GEN-LINE:|314-if|2|315-postAction
        } else {//GEN-LINE:|314-if|3|316-preAction
            for (int i = 0; i < znalezione.size(); i++) {
                    ListaPrzystankowForm.append((String) znalezione.elementAt(i), null);
            }
            switchDisplayable(null, ListaPrzystankowForm);//GEN-LINE:|314-if|4|316-postAction
        }//GEN-LINE:|314-if|5|314-postIf
        // enter post-if user code here
    }//GEN-BEGIN:|314-if|6|
    //</editor-fold>//GEN-END:|314-if|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: alert1 ">//GEN-BEGIN:|319-getter|0|319-preInit
    /**
     * Returns an initiliazed instance of alert1 component.
     * @return the initialized component instance
     */
    public Alert getAlert1() {
        if (alert1 == null) {//GEN-END:|319-getter|0|319-preInit
            // write pre-init user code here
            alert1 = new Alert("alert1", "Nie znaleziono przystanku.", null, AlertType.WARNING);//GEN-BEGIN:|319-getter|1|319-postInit
            alert1.setTimeout(2000);//GEN-END:|319-getter|1|319-postInit
            // write post-init user code here
        }//GEN-BEGIN:|319-getter|2|
        return alert1;
    }
    //</editor-fold>//GEN-END:|319-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField ">//GEN-BEGIN:|324-getter|0|324-preInit
    /**
     * Returns an initiliazed instance of textField component.
     * @return the initialized component instance
     */
    public TextField getTextField() {
        if (textField == null) {//GEN-END:|324-getter|0|324-preInit
            // write pre-init user code here
            textField = new TextField("Przystanek poczatkowy", null, 32, TextField.ANY);//GEN-LINE:|324-getter|1|324-postInit
            // write post-init user code here
        }//GEN-BEGIN:|324-getter|2|
        return textField;
    }
    //</editor-fold>//GEN-END:|324-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField1 ">//GEN-BEGIN:|325-getter|0|325-preInit
    /**
     * Returns an initiliazed instance of textField1 component.
     * @return the initialized component instance
     */
    public TextField getTextField1() {
        if (textField1 == null) {//GEN-END:|325-getter|0|325-preInit
            // write pre-init user code here
            textField1 = new TextField("Przystanek koncowy", null, 32, TextField.ANY);//GEN-LINE:|325-getter|1|325-postInit
            // write post-init user code here
        }//GEN-BEGIN:|325-getter|2|
        return textField1;
    }
    //</editor-fold>//GEN-END:|325-getter|2|

    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    public void pauseApp() {
        midletPaused = true;
    }

    public void destroyApp(boolean unconditional) {
    }
}
